<?php 

if(!isset($title) || $title == '') $title = 'Informe';
$nombreInforme = $title;

if ($xlsx) {
	$nombreInforme .= '.xlsx';
	$excel = 'Excel2007';
	header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');	
}
else {
	$nombreInforme .= '.xls';
	$excel = 'Excel5';
	header('Content-Type: application/vnd.ms-excel');
}

header("Content-Disposition: attachment;filename=" . $nombreInforme);
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $excel);
$objWriter->save('php://output');

$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
?>